package com.heima.search.listener;

import com.heima.model.search.pojo.SearchArticleVo;
import com.heima.search.service.ApArticleSearchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class ArticleIndexListener {

    @Resource
    private ApArticleSearchService apArticleSearchService;

    @RabbitListener(queues = "article.index")
    public void handleArticleIndex(SearchArticleVo searchArticleVo) {
        log.info("接收到文章索引更新消息，文章ID: {}", searchArticleVo.getId());
        try {
            apArticleSearchService.saveArticleToES(searchArticleVo);
            log.info("文章索引更新处理完成，文章ID: {}", searchArticleVo.getId());
        } catch (Exception e) {
            log.error("处理文章索引更新失败，文章ID: {}", searchArticleVo.getId(), e);
        }
    }
}
